package com.wenwan.manage.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.wenwan.manage.mapper.UserAuthenticationMapper;
import com.wenwan.manage.service.UserAuthenticationService;
import com.wenwan.manage.setting.RegExpSetting;
import com.wenwan.manage.setting.StatusSetting;
import com.wenwan.manage.util.Util;

@Service
public class UserAuthenticationServiceImpl implements UserAuthenticationService {

	@Autowired
	private UserAuthenticationMapper userAuthenticationMapper;

	@Override
	public Map<String, Object> create(String userId, String realName, String birthday, String address, String identity,
			String sex, String nation, String office, String validity, String phone) {
		// TODO Auto-generated method stub
		// DataToObject<Boolean> dto = new DataToObject<Boolean>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (userId != null && !userId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "userId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("userId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", userId);
		map.put("createTime", Util.getTime());
		map.put("updateTime", Util.getTime());
		map.put("userId", userId);
		map.put("realName", realName);
		map.put("birthday", birthday);
		map.put("address", address);
		map.put("identity", identity);
		map.put("sex", sex);
		map.put("nation", nation);
		map.put("office", office);
		map.put("validity", validity);
		map.put("phone", phone);

		Boolean data = userAuthenticationMapper.create(map);
		// dto.setData(data);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

	@Override
	public Map<String, Object> selectOneById(String id) {
		// TODO Auto-generated method stub
		// DataToObject<Boolean> dto = new DataToObject<Boolean>();
		Map<String, Object> dto = new HashMap<String, Object>();

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);

		Boolean data = userAuthenticationMapper.isExist(map);
		// dto.setData(data);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

	@Override
	public Map<String, Object> checkIdCard(String userId, MultipartFile multipartFile, Integer card_type,
			String token) {
		// TODO Auto-generated method stub
		// DataToObject<Object> dto = new DataToObject<Object>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (userId != null && !userId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "userId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("userId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (token != null && !token.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "token" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("token" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (card_type != null && card_type < 0) {
			dto.put("data", false);
			dto.put("msg", "card_type" + StatusSetting.MSG_10050_IS_CAN_NOT_LESS_ZERO);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("card_type" + StatusSetting.MSG_10050_IS_CAN_NOT_LESS_ZERO);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}
		return null;
		// return RenLiangHeShengUtil.checkIdCard(userId, multipartFile, card_type,
		// token);
	}

	@Override
	public Map<String, Object> faceLivegetfour(String userId, String token) {
		// TODO Auto-generated method stub
		// DataToObject<Object> dto = new DataToObject<Object>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (userId != null && !userId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "userId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("userId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (token != null && !token.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "token" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("token" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		return null;
		// return RenLiangHeShengUtil.faceLivegetfour(userId, token);
	}

}
